package net.thxjj.adminServer.controller;

import net.thxjj.adminServer.controller.base.BaseController;
import net.thxjj.adminServer.entity.LoginHadleEvent;
import net.thxjj.adminServer.entity.ResponseModel;
import net.thxjj.adminServer.entity.ResultEnum;
import net.thxjj.adminServer.entity.aep.*;
import net.thxjj.adminServer.entity.onenet.OnetEvent;
import net.thxjj.adminServer.mongodao.*;
import net.thxjj.adminServer.service.IMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/mongodb")
public class ImportToMongoController extends BaseController {

    @Autowired
    private MongoLoginDao mongoLoginDao;
    @Autowired
    private MongoProfileDao mongoProfileDao;
    @Autowired
    private MongoOnenetDao mongoOnenetDao;
    @Autowired
    private MongoHeartDao mongoHeartDao;
    @Autowired
    private MongoSmokeDao mongoSmokeDao;
    @Autowired
    private MongoEventDao mongoEventDao;
    @Autowired
    private MongoLoginHandleDao mongoLoginHandleDao;

    @Autowired
    private IMongoService iMongoService;


    /**
     * 导入Login
     * @return
     */
    @RequestMapping(value="/importLogin",method= RequestMethod.GET)
    @ResponseBody
    public Object importLogin(){

        List<LoginData> loginDataList = iMongoService.getLoginData();

        mongoLoginDao.saveAllData(loginDataList);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }


    /**
     * 导入ProfileLog
     * @return
     */
    @RequestMapping(value="/importProfileLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importProfileLog(){

        List<ProfileLog> profileLogList = iMongoService.getProfileLog();

        mongoProfileDao.saveAllData(profileLogList);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * 导入OnetLog
     * @return
     */
    @RequestMapping(value="/importOnetLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importOnetLog(){

        List<OnetEvent> onetEvents = iMongoService.getOnetEventLog();

        mongoOnenetDao.saveAllData(onetEvents);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * 导入HeartLog
     * @return
     */
    @RequestMapping(value="/importHeartLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importHeartLog(){

        List<HeartData> heartData = iMongoService.getHeartData();

        mongoHeartDao.saveAllData(heartData);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * 导入SmokeLog
     * @return
     */
    @RequestMapping(value="/importSmokeLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importSmokeLog(){

        List<SmokeData> smokeData = iMongoService.getSmokeData();

        mongoSmokeDao.saveAllData(smokeData);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * 导入DevLog
     * @return
     */
    @RequestMapping(value="/importDevLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importDevLog(){

        List<DevLog> smokeData = iMongoService.getEventData();

        mongoEventDao.saveAllData(smokeData);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * 导入Login_handle_log
     * @return
     */
    @RequestMapping(value="/importLoginHandleLog",method= RequestMethod.GET)
    @ResponseBody
    public Object importLoginHandleLog(){

        List<LoginHadleEvent> loginHadleEvents = iMongoService.getAllLoginHadleEvent();

        mongoLoginHandleDao.saveAllData(loginHadleEvents);

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

}
